package star.cloud.asme.system.permission;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import star.cloud.asme.base.dto.Result;
import star.cloud.asme.base.mybatis.IBaseController;

import java.util.List;

@RestController
@RequestMapping("/system/permission")
@Slf4j
@RequiredArgsConstructor
public class PermissionController implements IBaseController<Permission> {

    private final PermissionService permissionService;

    @Override
    public Result<Permission> insertOne(Permission entity) {
        return permissionService.insertOne(entity);
    }

    @Override
    public Result<?> physicalDeleteById(Long id) {
        return permissionService.physicalDeleteById(id);
    }

    @Override
    public Result<?> logicalDeleteById(Long id) {
        return permissionService.logicalDeleteById(id);
    }

    @Override
    public Result<Permission> updateOne(Permission entity) {
        return permissionService.updateOne(entity);
    }

    @Override
    public Result<Permission> getOneByCondition(String columnName, Object columnValue) {
        return permissionService.getOneByCondition(columnName, columnValue);
    }

    @Override
    public Result<List<Permission>> getListByConditions(Permission conditions) {
        return permissionService.getListByConditions(conditions);
    }

    @Override
    public Result<IPage<Permission>> getListByConditionsWithPage(Permission entity) {
        return permissionService.getListByConditionsWithPage(entity);
    }

    @GetMapping("/userId/{userId}")
    public Result<List<String>> getPermissionTextListByUserId(@PathVariable Long userId) {
        return permissionService.getPermissionTextListByUserId(userId);
    }

    //当进行权限操作时执行该操作
    @PutMapping("/resetPermissionListByRoleAndMenu")
    public Result<?> resetPermissionListByRoleAndMenu(PermissionDTO permissionDTO) {
        return permissionService.resetPermissionListByRoleAndMenu(permissionDTO);
    }

    @PostMapping("/selectPermissionTextListByRoleNameAndMenuTitle")
    public Result<List<String>> selectPermissionTextListByRoleNameAndMenuTitle(PermissionDTO permissionDTO) {
        return permissionService.selectPermissionTextListByRoleNameAndMenuTitle(permissionDTO);
    }

    @PostMapping("/selectPermissionListByRoleNameAndMenuTitle")
    public Result<List<Permission>> selectPermissionListByRoleNameAndMenuTitle(PermissionDTO permissionDTO) {
        return permissionService.selectPermissionListByRoleNameAndMenuTitle(permissionDTO);
    }
}